package com.yuyuan.upload.controller;

import com.yuyuan.common.domain.Result;
import com.yuyuan.upload.service.IUploadService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@Slf4j
@RestController
@RequestMapping("/upload")
public class UploadController {

    @Autowired
    private IUploadService uploadService;


    /**
     * 上传图片
     *
     * @param images 图片数组
     * @return 图片路径
     */
    @PostMapping("/images")
    public String uploadImages(@RequestParam("file") MultipartFile[] images) {
        return uploadService.uploadImages(images);
    }

    @PostMapping("/iconImage")
    public String uploadIconImage(@RequestParam("file") MultipartFile image) {
        return uploadService.uploadIconImage(image);
    }

    /**
     * 根据路径删除存储桶中的图片
     *
     * @param filePath 图片链接
     * @return 空
     */
    @GetMapping("/blog/delete")
    public Result deleteBlogImage(@RequestParam("name") String filePath) {
        return uploadService.deleteBlogImage(filePath);
    }

    /**
     * 获取存储桶临时凭证
     *
     * @return List
     */
    @GetMapping("/cos/tmpInfo")
    public Result getCosTmpInfo() {
        return uploadService.getCosTmpInfo();
    }

}
